package com.mpgame.database.mysql.mapper.game;

import com.mpgame.database.mysql.mapper.BaseMapper;
import com.mpgame.database.mysql.model.game.FamilyRelation;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.Param;

import java.util.List;

@Mapper
public interface FamilyRelationMapper extends BaseMapper<FamilyRelation> {
    
    @Insert("INSERT INTO family_relation (from_family_id, to_family_id, multiple) VALUES (#{fromFamilyId}, #{toFamilyId}, #{multiple})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(FamilyRelation familyRelation);

    @Select("SELECT * FROM family_relation WHERE id = #{id}")
    FamilyRelation selectById(@Param("id") int id);

    @Select("SELECT * FROM family_relation WHERE from_family_id = #{fromFamilyId} AND to_family_id = #{toFamilyId}")
    FamilyRelation selectByRelation(@Param("fromFamilyId") int fromFamilyId, @Param("toFamilyId") int toFamilyId);

    @Select("SELECT * FROM family_relation WHERE from_family_id = #{fromFamilyId}")
    List<FamilyRelation> selectByFromFamily(@Param("fromFamilyId") int fromFamilyId);

    @Select("SELECT * FROM family_relation")
    List<FamilyRelation> selectAll();

    @Update("UPDATE family_relation SET multiple = #{multiple} WHERE id = #{id}")
    int updateById(FamilyRelation familyRelation);
}
